package com.cabal.module;


import java.io.*;
import java.net.Socket;

public class ThreadSocketUploadClient implements Runnable {

    private String host;
    private int port;
    private String param;
    private Socket socket;

    public ThreadSocketUploadClient(String host, int port, String param, Socket socket) {
        this.host = host;
        this.port = port;
        this.param = param;
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            int i = 1;
            if(i < 65535) {
                try {
                    System.out.println(i);
                    DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
                    dos.writeUTF(param);
                    i++;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        String host = "82.156.4.197";
        int port = 38121;
        try {
            Socket s = new Socket(host, port);
            StringBuilder sb = new StringBuilder();
            for(int i=0; i<1000; i++){
                sb.append("caonima");
            }
            String result = sb.toString();

            for (int i = 0; i < 100; i++) {
                Thread clientThread = new Thread(new ThreadSocketUploadClient(host, port, result, s));
                clientThread.start();
            }
        } catch (Exception e) {

        }

    }
}
